package br.com.mundodaprata.store.testes;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ReflectionMain {
	
	public static void main(String[] args) throws Exception {
		Reflexive reflexive = new Reflexive();
		
		reflexive.setContent("ABCDE");
		
		Class<? extends Reflexive> type = 
				reflexive.getClass();
		
		Field[] fields = type.getDeclaredFields();
		
		for (Field field : fields) {
			if (field.getName().equals("content")){
				field.setAccessible(true);
				field.set(reflexive, "GHIJ");
				field.setAccessible(false);
			}
		}
		
		Method[] methods = type.getDeclaredMethods();
		
		for (Method method : methods) {
			System.out.println(method.getName());
			
			if(!method.getName().equals("execute")){
				continue;
			}
			
			try{
				method.setAccessible(true);
				
				if(method.getParameterTypes().length > 0){
					method.invoke(reflexive, 
							"comando qualquer");
					continue;
				}
				
				method.invoke(reflexive);
			}
			finally{
				method.setAccessible(false);
			}
		}
		
		System.out.println(reflexive.getContent());
	}

}